using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

internal sealed class SomeType {
   [DllImport("Kernel32", CharSet = CharSet.Unicode,
      EntryPoint="CreateEvent")]
   // This prototype is not robust
   private static extern IntPtr CreateEventBad(
		IntPtr pSecurityAttributes, Boolean manualReset, 
		Boolean initialState, String name);

   // This prototype is robust
	[DllImport("Kernel32", CharSet = CharSet.Unicode,
      EntryPoint = "CreateEvent")]
   private static extern SafeWaitHandle CreateEventGood(
		IntPtr pSecurityAttributes, Boolean manualReset, 
		Boolean initialState, String name);

   // This prototype is robust and type-safe
   [DllImport("Kernel32")]
   private static extern Boolean SetEvent(SafeWaitHandle swh);

   public static void SomeMethod() {
      IntPtr handle = CreateEventBad(IntPtr.Zero, false, false, null);
      SafeWaitHandle swh = CreateEventGood(IntPtr.Zero, false, false, null);
   }
}

public sealed class Program {
   public static void Main() {
      SomeType.SomeMethod();   
   }
}